package com.tecode.myBooks.filter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with Intellij IDEA.
 *
 * @Author: Gabriel
 * @Date: 2018-12-10
 * @Description:
 */
public class AutoLoginFilter extends  MyFilters {

	@Override
	public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
		//1.获得存放登录用户的session属性是否存在
		HttpSession session = request.getSession();
		//如果当前是没有登录的状态，则判断是否可以自动登录
		if(session.getAttribute("loginUser") == null){

			//从请求中获得是否存放了登录账号和密码的cookie对象
			Cookie[] cookies = request.getCookies();
			
			if (cookies != null && cookies .length >0){
				String account ="";
				String pwd ="";

				for (Cookie cookie : cookies) {
					
				}

				if(!account.equals("") && !pwd.equals("")){


				}
			}


		}

		filterChain.doFilter(request,response);
	}
}